package com.physique.tea.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.physique.tea.Pojo.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface QuestionMapper extends BaseMapper<Question> {
    // 增
    @Insert("INSERT INTO QUESTION (ID, CONTENT,PHYSIQUE) VALUES (#{ID}, #{CONTENT},#{PHYSIQUE})")
    @Options(useGeneratedKeys = true, keyProperty = "ID")
    int insertQuestion(Question question);

    // 删
    @Delete("DELETE FROM QUESTION WHERE ID = #{ID}")
    int deleteById(@Param("ID") Integer ID);

    // 改
    @Update("UPDATE QUESTION SET CONTENT = #{CONTENT},PHYSIQUE = #{PHYSIQUE} WHERE ID = #{ID}")
    int updateQuestion(Question question);

    // 查
    @Select("SELECT ID, CONTENT,PHYSIQUE FROM QUESTION WHERE ID = #{ID}")
    Question selectById(@Param("ID") Integer ID);

    @Select("SELECT ID, CONTENT,PHYSIQUE FROM QUESTION WHERE CONTENT LIKE '%' || #{KEYWORD} || '%'")
    List<Question> searchByContent(@Param("KEYWORD") String KEYWORD);

    @Select("SELECT ID, CONTENT,PHYSIQUE FROM QUESTION ORDER BY ID")
    List<Question> selectAll();

    @Select("SELECT SUBSTRING(CONTENT, 1, 50) AS SHORT_CONTENT FROM QUESTION")
    List<Map<String, Object>> selectShortContents();
}